import { FormTEditor, FormUpload } from '@/components'
import { errorTips, successTips } from '@/utils'
import { isTrue } from '@/utils/tools'
import { defineComponent, reactive } from 'vue'

export default defineComponent({
    name: 'BasicSystem',
    setup() {
        const rules = {
        }
        const pageState = reactive({
            activeKey: 'basic',
            loading: false,
            formData: {
                basic: {
                    contacts: '',
                    weChat: '',
                    mobile: '',
                    weChatAccount: ''
                }
            },
        })
        init()
        async function init() {
            const { success, data } = await API.server.seting.getSeting.request({
                code: 'system'
            })
            if (success) {
                pageState.formData = data.basic ? data : {
                    basic: {
                        contacts: '',
                        weChat: '',
                        mobile: ''
                    }
                }
            }
        }
        async function submit() {
            const { success } = await API.server.seting.createSeting.request({
                code: 'system',
                data: JSON.stringify(pageState.formData)
            })
            if (success) {
                successTips('保存成功')
            }
        }
        return () => <div style="background: #fff;padding:20px">
            <a-tabs v-model={[pageState.activeKey, 'activeKey']} >
                <a-tab-pane key="basic" tab="基础设置">
                    <a-form
                        labelCol={{ span: 6 }}
                        wrapperCol={{ span: 15 }}
                        model={pageState.formData}
                        rules={rules}
                        onFinish={submit}
                        style="width: 50%"
                    >
                        <a-row>
                            <a-col span={24}>
                                <a-form-item name={['basic', 'contacts']} label="联系人">
                                    <a-input v-model={[pageState.formData.basic.contacts, 'value']} />
                                </a-form-item>
                            </a-col>
                            <a-col span={24}>
                                <a-form-item name={['basic', 'mobile']} label="联系电话">
                                    <a-input v-model={[pageState.formData.basic.mobile, 'value']} />
                                </a-form-item>
                            </a-col>
                            <a-col span={24}>
                                <a-form-item name={['basic', 'weChatAccount']} label="微信号">
                                    <a-input v-model={[pageState.formData.basic.weChatAccount, 'value']} />
                                </a-form-item>
                            </a-col>
                            <a-col span={24}>
                                <a-form-item name={['basic', 'weChat']} label="联系方式二维码">
                                    <FormUpload v-model={[pageState.formData.basic.weChat, 'src']} ></FormUpload>
                                </a-form-item>
                            </a-col>
                        </a-row>
                        <div style={{ textAlign: 'center' }}>
                            <a-button type="primary" html-type="submit">
                                保存
                            </a-button>
                        </div>
                    </a-form>
                </a-tab-pane>
            </a-tabs>
        </div>
    }
})